﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
//using System.Web.UI.WebControls;
using FineUI;
using mydddd.BLL.other;


namespace mydddd.Web.Demo.sysRolepopedom
{
    public partial class RoleAdd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                mydddd.BLL.SysModule bll = new mydddd.BLL.SysModule();
                BaseTree.CreateTree(Tree1, bll.GetAllList(), "moduleName", "moduleIcon", "parentID", "moduleUrl", true, false, true, true);
            }
            
        }

        protected void Tree1_OnNodeCheck(object sender, TreeCheckEventArgs e)
        {
            if (e.Checked)
            {
                Tree1.CheckAllNodes(e.Node.Nodes);
            }
            else
            {
                Tree1.UncheckAllNodes(e.Node.Nodes);
            }
        }

        protected void Button_add_OnClick(object sender, EventArgs e)
        {
            TreeNode[] nodes = Tree1.GetCheckedNodes();

            StringBuilder sb = new StringBuilder();
            if (nodes.Length > 0)
            {
                foreach (TreeNode node in nodes)
                {
                    sb.AppendFormat(",{0}", node.NodeID);
                }
            }
            else
            {
                AlertQuestion("请选择页面模块！",false);
                return;
            }

            mydddd.BLL.sysRolepopedom bll = new mydddd.BLL.sysRolepopedom();
            mydddd.Model.sysRolepopedom mo = new mydddd.Model.sysRolepopedom();
            mo.rname = txb_name.Text;
            mo.state = 1;
            mo.moduleid = sb.ToString().Substring(1);

            int tempint = bll.Add(mo);
            if (tempint > 0)
            {

                //设置缓存
                BLL.SysModule sysModulebll=new BLL.SysModule();
                DataSet ds = sysModulebll.GetList(" id in (" + mo.moduleid + ") order by sort ");
                CacheHelper.Insert(BLL.sysRolepopedom.CacheName() + tempint, ds);

                AlertInfor("添加成功！", true);
            }
            else
            {
                Alert.Show("添加失败！");
            }


        }
    }
}